package com.mcxx.modules.miniSalvation.order.service.read;

import com.mcxx.modules.miniSalvation.order.dao.read.OrderInHouseReadDao;
import com.mcxx.modules.miniSalvation.order.dto.OrderDTO;
import com.mcxx.modules.miniSalvation.order.dto.OrderInHouseDTO;
import com.mcxx.modules.miniSalvation.order.entity.OrderEntity;
import com.mcxx.util.Constant;
import com.yinhai.ta404.core.service.BaseService;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@TaTransactional(readOnly = true)
public class InHouseReadService extends BaseService {
	@Autowired
	private OrderInHouseReadDao inHouseReadDao;
	@Autowired
	private OrderReadService orderReadService;


	public OrderInHouseDTO queryNewByOrderId(String orderId, String userAreaLevel){
		return inHouseReadDao.queryNewByOrderId(orderId, userAreaLevel);
	}


	public OrderInHouseDTO queryNewById(String inHouseId){
		return inHouseReadDao.queryNewById(inHouseId);
	}


	public List<OrderInHouseDTO> selectListByOrderId(String orderId, String userAreaLevel){
		return  inHouseReadDao.selectListByOrderId(orderId, userAreaLevel);
	}



	public int cntByOrderId(String orderId, String userAreaLevel){
		return inHouseReadDao.cntByOrderId(orderId, userAreaLevel);
	}



	public String getCheckResult(String orderId, String userAreaLevel){
		return  inHouseReadDao.getCheckResult(orderId, userAreaLevel);
	}

	public OrderInHouseDTO queryLastInHouseRecord(String orderId, String userAreaLevel){
		OrderEntity orderEntity = orderReadService.getById(orderId);

		if(Constant.BizStateNew.COUNTY_IN_HOUSE_ING.equals(orderEntity.getBizState())
			|| Constant.BizStateNew.IN_HOUSE_ING_AGAIN.equals(orderEntity.getBizState())
			|| Constant.BizStateNew.IN_HOUSE_ING.equals(orderEntity.getBizState())){
			return inHouseReadDao.queryNewByOrderId(orderId, userAreaLevel);
		}
		return new OrderInHouseDTO();
	}
}
